const { Model } = require('../index');

class UserStock extends Model {
    static get tableName() {
        return 'user_stock';
    }

    static get relationMappings() {
        return {
            // Create a mapping with the user model
            //  a user_stock belongs to a user
            user: {
                relation: Model.BelongsToOneRelation,
                modelClass: `${__dirname}/user.js`,
                // Where the two are joined
                join: {
                    from: 'user_stock.userId',
                    to: 'user.id'
                }
            },
            //  a user_stock is from a stock
            stock: {
                relation: Model.BelongsToOneRelation,
                modelClass: `${__dirname}/stock.js`,
                // Where the two are joined
                join: {
                    from: 'user_stock.stockId',
                    to: 'stock.id'
                }
            },//  A user_stock has many user_stock_tag
            user_stock_tag: {
                relation: Model.HasManyRelation,
                modelClass: `${__dirname}/user_stock_tag.js`,
                // Where the two are joined
                join: {
                    from: 'user_stock.id',
                    to: 'user_stock_tag.user_stock_id'
                }
            }
        };
    }
}

module.exports = UserStock;
//a = u.tableName;